import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class Input extends HookWidget {
  final String placeholder;
  final IconData icon;
  final bool isPassword;
  final TextEditingController controller;
  final FontWeight fontWeight;
  final Color color;
  final Color placeholderColor;
  final Color backgroundColor;
  final double fontSize;
  final double iconSize;
  Input(
      {this.placeholder = '',
      this.icon,
      this.isPassword = false,
      this.fontWeight = FontWeight.normal,
      this.color = const Color.fromARGB(255, 100, 100, 100),
      this.placeholderColor = Colors.grey,
      this.backgroundColor = const Color.fromARGB(0, 0, 0, 0),
      this.fontSize = 16,
      this.iconSize = 18,
      this.controller});
  @override
  Widget build(BuildContext context) {
    final passwordVisible = useState(false);

    final textStyle = TextStyle(
        color: color,
        fontWeight: fontWeight,
        fontSize: fontSize,
        textBaseline: TextBaseline.alphabetic);
    final hintStyle = TextStyle(
        color: placeholderColor, fontWeight: fontWeight, fontSize: fontSize);

    Widget prefix;
    if (icon != null) {
      prefix = Padding(
        padding: EdgeInsets.fromLTRB(15, 0, 6, 0),
        child: Icon(
          icon,
          size: iconSize,
          color: Colors.grey,
        ),
      );
    }
    return Container(
      padding: EdgeInsets.fromLTRB(icon == null ? 22 : 0, 0, 0, 0),
      decoration: BoxDecoration(
          color: backgroundColor, borderRadius: BorderRadius.circular(30)),
      child: TextField(
        controller: controller,
        obscureText: isPassword && !passwordVisible.value,
        style: textStyle,
        cursorColor: textStyle.color,
        textAlignVertical: TextAlignVertical.center,
        decoration: InputDecoration(
            hintText: placeholder,
            hintStyle: hintStyle,
            prefixIcon: prefix,
            prefixIconConstraints: BoxConstraints(minHeight: 20),
            border: InputBorder.none,
            suffixIcon: Visibility(
              visible: isPassword,
              child: IconButton(
                icon: Icon(
                  passwordVisible.value
                      ? CupertinoIcons.eye_slash_fill
                      : CupertinoIcons.eye_fill,
                  size: 18,
                  color: Colors.black26,
                ),
                onPressed: () {
                  passwordVisible.value = !passwordVisible.value;
                },
              ),
            )),
      ),
    );
  }
}
